<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input 
        v-model="listQuery.opUser" 
        placeholder="操作人" 
        class="filter-item search-input" 
        clearable  
        @keyup.enter.native="handleFilter"/>
      <el-date-picker v-model="listQuery.fromDate" placeholder="操作时间（开始）" 
        type="datetime"
         style="width : 200px;" class="search-input filter-item" />
      <el-date-picker v-model="listQuery.toDate" placeholder="操作时间（结束）" 
        type="datetime"
          style="width : 200px;" class="search-input filter-item" />
      <el-input v-model="listQuery.lineId" placeholder="线路ID" class="filter-item search-input"  clearable/>
      <el-input v-model="listQuery.lineName" placeholder="线路名" class="filter-item search-input" clearable @keyup.enter.native="handleFilter" />
      <el-select
        v-model="listQuery.peerId"
        placeholder="分公司"
        clearable
        style="width: 190px"
        class="filter-item search-input"
      >
        <el-option v-for="item in peerOptions" :key="item.peerId" :label="item.name" :value="item.peerId" />
      </el-select>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <!--      <el-table-column label="线路ID" width="80px" align="center">-->
      <!--        <template slot-scope="{row}">-->
      <!--          <span>{{ row.ID }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
     
      <el-table-column label="操作人" align="center">
        <template slot-scope="{row}">
          <span v-html="row.opUser"></span>
        </template>
      </el-table-column>
      <el-table-column label="操作时间" align="center">
        <template slot-scope="{row}">
          <span v-html="row.opTime "></span>
        </template>
      </el-table-column>
      <el-table-column label="线路ID" align="center">
        <template slot-scope="{row}">
          <span v-html="row.lineId"></span>
        </template>
      </el-table-column>
      <el-table-column label="线路名" align="center">
        <template slot-scope="{row}">
          <span v-html="row.lineName"></span>
        </template>
      </el-table-column>
      <el-table-column label="增加库存量" align="center">
        <template slot-scope="{row}">
          <span v-html="row.amount"></span>
        </template>
      </el-table-column>
      <el-table-column label="操作后库存余额" align="center">
        <template slot-scope="{row}">
          <span v-html="row.totalAmount"></span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.perPage"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { stockLog } from '@/api/logManagement '
import { listSelection } from '@/api/selectOptions'
import Pagination from '@/components/Pagination'

export default {
  components: {
    Pagination
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page : 1 ,
        perPage : 20 ,
        opUser : undefined,//操作人，电话号
        fromDate : undefined,//操作时间（开始）
        toDate : undefined,//操作时间（结束）
        lineId : undefined,// 线路ID",
        lineName : undefined,//线路名
        peerId: undefined
      },
      peerOptions: undefined,
    }
  },
  created() {
    this.getPeerOptions()
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      stockLog(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.total
        this.listLoading = false
      })
    },
    getPeerOptions() {
      listSelection().then(response => {
        this.peerOptions = response.data
      })
    },
    handleFilter() {
      var regex = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
      var opUser = this.listQuery.opUser;
      if(opUser != null && opUser != '' && opUser != undefined){
        if(!regex.test(this.listQuery.opUser)){
          this.$notify({
            title: '提示',
            message: '操作人(手机号)不合法',
            type: 'error',
            duration: 2000
          })
          return false;
        }
      }
      this.listQuery.page = 1
      this.getList()
    },
  }
}
</script>

<style>
.search-input {
  width: 150px;
  margin-right: 15px;
}

</style>
